package com.mfl.controller.user;

import com.mfl.common.PageResult;
import com.mfl.common.Result;
import com.mfl.pojo.dto.KYCourseVideoPageQueryDTO;
import com.mfl.pojo.vo.KYCourseVideoVO;
import com.mfl.service.KYCourseVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController("userCourseController")
@RequestMapping("/cky/user/courseVideo")
@Slf4j
public class CourseVideoController {

    @Autowired
    private KYCourseVideoService kyCourseVideoService;

    /**
     * 分页查询课程视频
     * @param kyCourseVideoPageQueryDTO
     * @return
     */
    @GetMapping("/pageQueryCourseVideo")
    public Result<PageResult> pageQueryCourseVideo(KYCourseVideoPageQueryDTO kyCourseVideoPageQueryDTO){
        log.info("分页查询课程视频：{}", kyCourseVideoPageQueryDTO);
        PageResult pageResult = kyCourseVideoService.page(kyCourseVideoPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 根据id查询课程视频
     * @param id
     * @return
     */
    @GetMapping("/getCourseVideoById")
    public Result<KYCourseVideoVO> getCourseVideoById(int id){
        log.info("根据id查询课程视频：{}", id);
        KYCourseVideoVO kyCourseVideoVO = kyCourseVideoService.getCourseVideoById(id);
        return Result.success("", kyCourseVideoVO);
    }

    /**
     * 修改点击量
     * @param id
     * @return
     */
    @PutMapping("/updateClickCount")
    public Result updateClickCount(@RequestBody Map<String, Object> requestBody){
        Integer id = (Integer) requestBody.get("id");
        log.info("根据id修改点击量：{}", id);
        kyCourseVideoService.updateClickCount(id);
        return Result.success("", null);
    }
}
